<template>
	<view>
		<u-toast ref="uToast" />
		<view v-if="show" class="loading_view">
		  <u-loading mode="circle" size="50"></u-loading>
		  <view class="messgae">
			加载中...
		  </view>
		 </view>
		<view v-else>
		<view class='s_head'>
			<view class="head" style="width:100%;height:430rpx;">
				<image :src="view.s_icon"></image>
			</view>
			<view class='title'>
				<view class='name'>{{view.s_name}}</view>
				<view class='descript'>{{view.s_quotations}}</view>
			</view>
		</view>
		<u-tabs :list="list" active-color="#EA4389" :is-scroll="false" :current="current" @change="change"></u-tabs>
		<view v-if="current==0" class='brief'>
			<scroll-view scroll-y class="scr">
			<view class='img'>
				<image :src='teacher.t_icon'></image>
			</view>
			<view class='right'>
				<view class='name'>{{teacher.t_name}}</view>
				<view class='title'>{{teacher.t_job}}</view>
			</view>
			<view class='info'>
				<rich-text :nodes="teacher.t_descript"></rich-text>
			</view>
			<view class='course'>
				<view class='c_head'>课程简介</view>
				<view class='c_cont'>
					<rich-text :nodes="view.s_descript"></rich-text>
				</view>
			</view>
			</scroll-view>
		</view>
		<view v-else>
			<scroll-view scroll-y class="chapter">
				<view class="c_list" v-for="(v,k) in chapter" :key="k">
					<view class="c_left">
						<view class="name">
							<view class="title">{{v.s_name}}</view>
						</view>
						<view class="time">{{v.s_descript}}</view>
					</view>
					<view class="c_right">
						<view class="c_btn" @click="onUrl" data-url="/pages/secret/chapter?id=" :data-get="v.s_id">{{v.s_type==1?'播放':'阅读'}}</view>
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="btn" v-if="isM==0" @click="onPay">解锁课程 ￥{{view.s_money}}</view>
		<view class="btn bak" v-else>已解锁</view>
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return{
				list: [{
					name: '课程介绍'
				}, {
					name: '课程章节'
				}],
				current: 0,
				view:[],
				teacher:[],
				chapter:[],
				id:null,
				show:true,
				isM:0
			}
		},onLoad(e){
			var id=typeof(e.id)
			
			if(id!='undefined'){
				this.id=Number(e.id)
				
				this.onView();
			}else{
				this.show=false;
			}
		},methods:{
			onPay(){
				var token=this.$store.state.Authorization;
				
				if(token){
					uni.navigateTo({
					    url: '/pages/secret/pay?id='+this.view.s_id
					});
				}else{
					this.$refs.uToast.show({
						title: '未登录',
						type:'default'
					});
				}
			},
			onUrl(e){
				var url=e.currentTarget.dataset.url;
				
				var get=e.currentTarget.dataset.get;
				
				uni.navigateTo({
				    url: url+get
				});
			},
			change(index) {
				this.current = index;
			},
			onView(){
				var that=this;
				
				this.show=true;
				
				this.$request({
					url:'/secret/view',
					data:{id:this.id},
					success(res){
						if(res.data.code==1){
							that.view=res.data.data.view;
							
							that.teacher=res.data.data.teacher;
							
							that.chapter=res.data.data.chapter;
							
							that.isM=res.data.data.isM;
							
							that.show=false;
						}else{
							that.show=false;
							
							that.$refs.uToast.show({
								title: res.data.msg,
								type:'error'
							});
						}
					},fail(){
						that.$refs.uToast.show({
							title: '网络繁忙',
							type:'warning'
						});
					}
				})
			}
		}
	}
</script>

<style src='../../static/css/secretView.css' scoped>
</style>
